package com.wing.cms.dao;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.wing.cms.domain.Placeholder;
import com.wing.common.CommonSpringJDBC;
import com.wing.common.util.PageBean;

@Repository
public class PlaceholderDao extends CommonSpringJDBC<Placeholder, String> {

	public PageBean findPageList(int currentPage, int pageSize, Object... args) {
		String where= " 1=1 ";
		String sql1=" SELECT * FROM cms_placeholder where "+where+" ORDER BY id ASC " +
			" LIMIT "+(currentPage-1) * pageSize+","+pageSize;
		String sql2 = "select count(id) from  cms_placeholder  where"+where;
		String[] sqlArray = {sql1,sql2 };
		return super.findPageList(sqlArray, currentPage, pageSize);
	}
	
	
	public List<Map<String, Object>> findPortletIdByAssociateId(String chanId, String hid,String lid ) {	
		String sql = "select t.portletid,t.portletype from cms_placeholder t where t.channelid=? and t.placeholderid=? and t.layoutid = ? order by order_num";
		Object [] objs = {chanId,hid,lid};
		return super.getSimpleJdbcTemplate().queryForList(sql,objs);
	}
	
	public void updatePlace(String column_id,String portletId,int order_num){
		String sql = " UPDATE cms_placeholder SET placeholderid = ? , order_num = ? where portletId = ?";
		Object [] objs = {column_id,order_num,portletId};
		super.getSimpleJdbcTemplate().update(sql, objs);
	}
	
	
	public void deleteByPortletId(String portletId){
		String sql = " delete from cms_placeholder where portletId = ?";
		Object [] objs = {portletId};
		super.getSimpleJdbcTemplate().update(sql, objs);

	}
}
